--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
subscription_settings.mu main (dac94b89) Text, 5.01 KB
import os
import main
from main import conf
debug = False
if "DEBUG" in os.environ:
if os.environ["DEBUG"].lower() == "true":
debug = True
import traceback
def list_subscriptions():
print(">>Your subscriptions:")
query_results = main.query_database(
f"SELECT sub_id, post_id FROM subscriptions WHERE username = '{username}' AND post_id != '$new$'"
)
for result in query_results:
post_title = main.query_database(
f"SELECT title FROM posts WHERE post_id = '{result[1]}'"
)[0][0]
print(
f" {post_title}}]"
)
def print_fields():
print(">Subscription Settings")
new_post_notification_string = ""
if (
len(
main.query_database(
f"SELECT sub_id FROM subscriptions WHERE username = '{username}' AND post_id = '$new$'"
)
)
== 1
):
new_post_notification_string = "|*"
print(
f" Notifications on new posts"
)
print()
print(
f"Save"
)
print()
if (
len(
main.query_database(
f"SELECT sub_id FROM subscriptions WHERE username = '{username}' AND post_id != '$new$'"
)
)
== 0
):
print(">>You have no subscriptions")
else:
list_subscriptions()
print(">")
print()
print(
)
try:
session = main.handle_ids()
main.print_header(session, reload=True)
action = ""
new_post_notification = False
for env_variable in os.environ:
if env_variable == "var_action":
action = os.environ[env_variable]
elif (
env_variable == "field_new_post_notification"
and os.environ[env_variable] == "yes"
):
new_post_notification = True
if not conf.notifications_enabled:
print(">Notifications are disabled.")
elif not session.is_logged_in():
print(">You are not logged in.")
else:
if action != "":
main.verify_link_id()
username = session.get_username()
all_selected = ""
if action == "select_all" and main.verify_link_id():
all_selected = "|*"
elif action == "save" and main.verify_link_id():
if (
new_post_notification
and len(
main.query_database(
f"SELECT sub_id FROM subscriptions WHERE username = '{username}' AND post_id = '$new$'"
)
)
== 0
):
main.execute_sql(
f"INSERT INTO subscriptions (username, post_id) VALUES ('{username}', '$new$')"
)
elif not new_post_notification:
main.execute_sql(
f"DELETE FROM subscriptions WHERE post_id = '$new$' AND username = '{username}'"
)
elif action == "delete" and main.verify_link_id():
subscriptions = main.query_database(
f"SELECT sub_id FROM subscriptions WHERE username = '{username}' AND post_id != '$new$'"
)
for subscription in subscriptions:
if (
os.getenv("field_selected_" + str(subscription[0]), default="no")
== "yes"
):
main.execute_sql(
f"DELETE FROM subscriptions WHERE sub_id = {subscription[0]}"
)
print_fields()
main.close_database()
except:
print("An error occured")
if debug:
traceback.print_exc()
exit(1)
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────